-- CALC_USER_DODGE
-- 计算玩家闪避

return function(user)
    local dodge = user.dbase:query("dodge", 0);

    local combine = PropM.combine;
    local apply = PropM.apply;
    local fetchProps = PropM.fetchProps;
    local trigger = PropM.trigger;

    -- 1. 百分比加成
    local propId = PropM.getPropId("attrib");
    local prop = combine(user, propId, "dodge");
    dodge = apply(prop, dodge);

    -- 2. 绝对值加成
    propId = PropM.getPropId("attrib2");
    prop = combine(user, propId, "dodge");
    dodge = apply(prop, dodge);

    -- 生命低于50%增加闪避
    local props = fetchProps(user, "hp_to_dodge");
    local addon = 0;
    for _, prop in ipairs(props) do
        dodge = trigger(user, prop[1], prop[2], dodge);
    end

    -- 阵营闪避
    local pet = user:getActivePet();
    local classId = pet.classId;
    local campId = CampM.getPetCamp(classId);
    prop = combine(user, "camp_dodge", campId);
    dodge = apply(prop, dodge);

    -- 3. 被削弱
    prop = combine(user, "reduce_attrib", "dodge");
    dodge = apply(prop, dodge);

    -- 4. 被削弱
    prop = combine(user, "reduce_attrib2", "dodge");
    dodge = apply(prop, dodge);

    -- 闪避上限
    local maxDodge = 30;
    prop = combine(user, "dodge_limit", 1);
    maxDodge = apply(prop, maxDodge);

    -- 阵营闪避上限
    prop = combine(user, "camp_max_dodge", campId);
    maxDodge = apply(prop, maxDodge);

    return math.min(dodge, maxDodge);
end
